package main.java.indi.zyj.sword;

import java.util.HashMap;

public class FindNthDigit {

    public int findNthDigit(int n) {
        long base = 1, digitCnt = 1;
        while (n > base * 9 * digitCnt) {
            n -= (base * 9 * digitCnt);
            base *= 10;
            ++digitCnt;
        }
        --n;
        return getKthDigit(base + n / digitCnt, n % digitCnt);
    }

    private int getKthDigit(long num, long k) {
        return String.valueOf(num).charAt((int) k) - '0';
    }
}
